package com.hwadee.teachingprocessmanagementsystem.service.base.impl;

import com.hwadee.teachingprocessmanagementsystem.entity.GraduationReview;
import com.hwadee.teachingprocessmanagementsystem.dao.GraduationReviewDao;
import com.hwadee.teachingprocessmanagementsystem.service.base.GraduationReviewService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import jakarta.annotation.Resource;

/**
 * 毕业审核表(GraduationReview)表服务实现类
 *
 * @author makejava
 * @since 2024-07-11 14:20:03
 */
@Service("graduationReviewService")
public class GraduationReviewServiceImpl implements GraduationReviewService {
    @Resource
    private GraduationReviewDao graduationReviewDao;

    /**
     * 通过ID查询单条数据
     *
     * @param reviewId 主键
     * @return 实例对象
     */
    @Override
    public GraduationReview queryById(Integer reviewId) {
        return this.graduationReviewDao.queryById(reviewId);
    }

    /**
     * 分页查询
     *
     * @param graduationReview 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<GraduationReview> queryByPage(GraduationReview graduationReview, PageRequest pageRequest) {
        long total = this.graduationReviewDao.count(graduationReview);
        return new PageImpl<>(this.graduationReviewDao.queryAllByLimit(graduationReview, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param graduationReview 实例对象
     * @return 实例对象
     */
    @Override
    public GraduationReview insert(GraduationReview graduationReview) {
        this.graduationReviewDao.insert(graduationReview);
        return graduationReview;
    }

    /**
     * 修改数据
     *
     * @param graduationReview 实例对象
     * @return 实例对象
     */
    @Override
    public GraduationReview update(GraduationReview graduationReview) {
        this.graduationReviewDao.update(graduationReview);
        return this.queryById(graduationReview.getReviewId());
    }

    /**
     * 通过主键删除数据
     *
     * @param reviewId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer reviewId) {
        return this.graduationReviewDao.deleteById(reviewId) > 0;
    }
}
